/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.j2meturk.main;

import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.midlet.MIDlet;

/**
 *
 * @author eray(dot)ince(at)gmail(dot)com
 */
public class ProgressBar extends Canvas {

    MIDlet m = null;
    Font font;
    public static Thread th = null;
    Image logoS = null;
    int w = 0, h = 0, Iw = 0, Ih = 0;
    int x = 0;
    Timer timer = null;
    final static int space = 3; //Space px between highlighted images
    public ProgressBar(MIDlet temp,String ImagePath) throws IOException {
        m = temp;
        w = getWidth();
        h = getHeight();
        TimerTask task = new TimerTask() {

            public void run() {
                if (x == 2) {
                    x = 0;
                } else {
                    x++;
                }
                repaint();
            }
        };
        timer = new Timer();
        timer.schedule(task, 100, 500);
        font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);
        logoS = Image.createImage(ImagePath);
        Iw = logoS.getWidth();
        Ih = logoS.getHeight();
        this.setFullScreenMode(true);
        Display.getDisplay(this.m).setCurrent(this);
        repaint();
    }

    protected void paint(Graphics g) {
        g.setGrayScale(255);
        g.fillRect(0, 0, w, h);
        g.setColor(105, 105, 105);
        g.setFont(font);
        try {
            if (x == 0) {
                g.drawImage(logoS, w / 2 - (Iw + Iw/2 + space), h / 2, 16 | 4);
                g.drawString("Loading...", w / 2 - (Iw + Iw/2 + space), h / 2 + Ih, 16 | 4);
            }
            else if (x == 1) {
                g.drawImage(logoS, w / 2 - (Iw + Iw/2 + space), h / 2, 16 | 4);
                g.drawImage(logoS, w / 2 - Iw/2, h / 2, 16 | 4);
                g.drawString("Loading...", w / 2 - (Iw + Iw/2 + space), h / 2 + Ih, 16 | 4);
            }
            else if (x == 2) {
                g.drawImage(logoS, w / 2 - (Iw + Iw/2 + space), h / 2, 16 | 4);
                g.drawImage(logoS, w / 2 - Iw/2, h / 2, 16 | 4);
                g.drawImage(logoS, w / 2 + Iw/2 + space, h / 2, 16 | 4);
                g.drawString("Loading...", w / 2 - (Iw + Iw/2 + space), h / 2 + Ih, 16 | 4);
            }
            else {
            }
        } catch (Exception ex) {
            System.out.println(ex);
        }

    }
}
